package 补充.集合框架;

import java.util.Comparator;
import java.util.TreeSet;

class Student{
    private Integer age;

    public Student(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                '}';
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}
class MyComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        if(o1 instanceof Student && o2 instanceof Student){
            Student s1 = (Student)o1;
            Student s2 = (Student)o2;
            if(s1.getAge() > s2.getAge()){
                return -1;
            }else if(s1.getAge() < s2.getAge()){
                return 1;
            }
        }
        return 0;
    }
}
public class TextTreeSetSort {
    public static void main(String[] args) {
        TreeSet<Student> students = new TreeSet<>(new MyComparator());
        students.add(new Student(100));
        students.add(new Student(22));
        students.add(new Student(33));
        students.add(new Student(40));

        students.add(new Student(55));
        System.out.println(students);
    }

}
